var		appCallback = new AppCallback ();

var		fta_ws = new FTA_WS (appCallback);
//var		fta_ws = new FTA_WS ();

function doFetchLatestNews () {
	
	fta_ws.fetchLatestNews ();
}

function updateLatestNews (newHTML){

	document.getElementById("latestNewsFeedContainer").innerHTML = newHTML;
}
function doClick () {
	try {
		var alertString = "";
		
		var		first_name = document.getElementById ("first_name").value;
		if (first_name == "" || first_name == null) {
			alertString += "first name\n";
		}
		
		var		last_name = document.getElementById ("last_name").value;
		if (last_name == "" || last_name == null) {
			alertString += "last name\n";
		}
		
		var		email = document.getElementById ("email").value;
		if (email == "" || email == null) {
			alertString += "email\n";
		}

		if (!isValidEmail(email)) {
			alertString = "please enter a valid email address.\n";
			alert(alertString);
			return;
		}

		var		zip = document.getElementById ("zip").value;
		if (zip == "" || zip == null) {
			alertString += "zip code\n";
		}
		if (zip.length > 10) {
			alertString = "zip/country code must be less than 10 characters.\n";
			alert(alertString);
			return;
		}
		
		if (alertString != "") {
			alertString = "Please complete the following fields before submitting:\n" + alertString;
			alert(alertString);
			return;
		}

		if (!fta_captcha.isValid()) {
			alert("Please ensure that the text matches the security word.");
			return;
		}

		var		click_x = document.getElementById ("click_x").value;
		var		click_y = document.getElementById ("click_y").value;
		var		keep_me_updated = document.getElementById ("keep_me_updated").checked;
	
		if (keep_me_updated == true) {
			keep_me_updated = 1; 
		}
		else {
			keep_me_updated = 0;
		}

		document.getElementById("takeActionTitle").innerHTML = "Thank you.";
		document.getElementById("takeActionSkip").style.visibility = "visible";
		
		document.getElementById("submitMessage").style.display = "none";
		document.getElementById("savingMessage").style.display = "block";


		// We are not passing country in for submissions
		fta_ws.click (click_x, click_y, first_name, last_name, email, zip, "US", keep_me_updated);
	} catch (e) { 
		alert ("doClick() threw an exception: " + e); 
	}
}

function doFCCEmail() {
	try {
		
		var alertString = "";
		
		var	first_name = document.getElementById("fcc_first_name").value;
		if (first_name == "" || first_name == null) {
			alertString += "first name\n";
			flagFCCInputLabel("fcc_first_name_label");
		}
		else {
			clearFCCInputLabel("fcc_first_name_label");
		}

		var	last_name = document.getElementById("fcc_last_name").value;
		if (last_name == "" || last_name == null) {
			alertString += "last name\n";
			flagFCCInputLabel("fcc_last_name_label");
		}
		else {
			clearFCCInputLabel("fcc_last_name_label");
		}

		var	email = document.getElementById("fcc_email").value;
		if (email == "" || email  == null) {
			alertString += "email\n";
			flagFCCInputLabel("fcc_email_label");
		}
		else {
			clearFCCInputLabel("fcc_email_label");
		}

		var	city = document.getElementById("fcc_city").value;
		if (city == "" || city  == null) {
			alertString += "city\n";
			flagFCCInputLabel("fcc_city_label");
		}
		else {
			clearFCCInputLabel("fcc_city_label");
		}

		var		state = document.getElementById("fcc_state");
		if (state.selectedIndex == 0) {
			alertString += "state\n";
			flagFCCInputLabel("fcc_state_label");
		}
		else {
			clearFCCInputLabel("fcc_state_label");
		}

		var	zip = document.getElementById("fcc_zip").value;
		if (zip == "" || zip == null) {
			alertString += "zip code\n";
			flagFCCInputLabel("fcc_zip_label");
		}
		else {
			clearFCCInputLabel("fcc_zip_label");
		}

		if (alertString != "") {
			alertString = "Please complete the following fields before submitting:\n" + alertString;
			alert(alertString);
			return;
		}






		if (first_name.length > 50) {
			flagFCCInputLabel("fcc_first_name_label");
			alert("first name must be less than 50 characters");
			return;
		}
		else {
			clearFCCInputLabel("fcc_first_name_label");
		}
		
		if (last_name.length > 50) {
			flagFCCInputLabel("fcc_last_name_label");
			alert("last name must be less than 50 characters");
			return;
		}
		else {
			clearFCCInputLabel("fcc_last_name_label");
		}
		
		if (email.length > 100) {
			flagFCCInputLabel("fcc_email_label");
			alert("email must be less than 10 characters.");
			return;
		}
		else {
			clearFCCInputLabel("fcc_email_label");
		}

		var	a1 = document.getElementById("fcc_address1").value;
		if (a1.length > 40) {
			flagFCCInputLabel("fcc_address1_label");
			alert("address 1 must be less than 50 characters");
			return;
		}
		else {
			clearFCCInputLabel("fcc_address1_label");
		}

		var		a2 = document.getElementById("fcc_address2").value;
		if (a2.length > 40) {
			flagFCCInputLabel("fcc_address2_label");
			alert("address 2 must be less than 50 characters");
			return;
		}
		else {
			clearFCCInputLabel("fcc_address2_label");
		}
		
		if (city.length > 40) {
			flagFCCInputLabel("fcc_city_label");
			alert("city must be less than 40 characters.");
			return;
		}
		else {
			clearFCCInputLabel("fcc_city_label");
		}
		
		if (zip.length > 10) {
			flagFCCInputLabel("fcc_zip_label");
			alert("zip code must be less than 10 characters.");
			return;
		}
		else {
			clearFCCInputLabel("fcc_zip_label");
		}

		if (!isValidEmail(email)) {
			flagFCCInputLabel("fcc_email_label");
			alert("please enter a valid email address.");
			return;
		}
		else {
			clearFCCInputLabel("fcc_email_label");
		}

		var selectedState = state.options[state.selectedIndex].value;

		var 	changed = document.getElementById("fcc_changed").value;
		var 	submission = ""
	
		if (changed != "0") {
			submission = document.getElementById("fccTextArea").value;
		}
	
		//alert (first_name + "\n" + last_name + "\n" + a1 + "\n" + a2 + "\n" + city + "\n" + selectedState + "\n" + zip + "\n" + email + "\n" + changed + "\n" + submission);
		//document.getElementById("fcc_submitMessage").style.display = "none";
		//document.getElementById("fcc_savingMessage").style.display = "block";
		keep_me_updated = document.getElementById("fcc_keep_me_updated").checked;

		if (keep_me_updated == true) {
			reveal_keepMeUpdated = 1; 
		}
		else {
			reveal_keepMeUpdated = 0;
		}
		
		resetFCCInputLabels();
		
		reveal_firstName = first_name;
		reveal_lastName = last_name;
		reveal_email = email;
		reveal_zip = zip;

		fta_ws.fccEmail (first_name, last_name, a1, a2, city, selectedState, zip, email, changed, submission);
	} 
	catch (e) {
		alert ("doFCCEmail() threw an exception: " + e); 
	}
}

function getLast10() {
	try {
		fta_ws.last10();
	} 
	catch (e) {
		alert ("getLast10() threw an exception: " + e); 
	}
}